<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>函数式组件使用props</title>
</head>

<body>
    <div id="test"></div>
    <script type="text/javascript" src="../js/react.development.js"></script>
    <script type="text/javascript" src="../js/react-dom.development.js"></script>
    <script type="text/javascript" src="../js/babel.min.js"></script>
    <!-- 引入prop-types,用于对组件标签属性进行限制 -->
    <script type="text/javascript" src="../js/prop-types.js"></script>
    <script type="text/babel">
        //1 创建类式组件
        function Person(props) {
            const { name, age, sex } = props
            return (
                <ul>
                    <li>姓名：{name}</li>
                    <li>性别：{sex}</li>
                    <li>年龄：{age + 1}</li>
                </ul>
            )
        }
        //进行类型和必要性
        Person.propTypes = {
            name: PropTypes.string.isRequired,
            sex: PropTypes.string,
            age: PropTypes.number,
        }
        //默认值
        Person.defaultProps = {
            sex: '男',
            age: 0
        }
        //2 渲染组件到页面
        ReactDOM.render(<Person name='小李' />, document.getElementById('test'))
    </script>
</body>

</html>